﻿using Autofac;
using Pay.Cache;
using Pay.Dal;
using Pay.DalImplement;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pay.Container
{
    public static class LocManager
    {

        /// <summary>
        /// 获取
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T Resolve<T>()
        {

            if (container == null)
            {
                Register();
            }

            return container.Resolve<T>();

        }

        private static IContainer container = null;
        /// <summary>
        /// 注入
        /// </summary>
        public static void Register()
        {
            var build = new ContainerBuilder();
            //注入
            build.RegisterType<Test>().As<ITest>().InstancePerLifetimeScope();
            build.RegisterType<RedisCacheManager>().As<ICacheManager>().InstancePerLifetimeScope();
            build.RegisterType<UserDalImplement>().As<IUserDal>().InstancePerLifetimeScope();
            build.RegisterType<RoleDalImplement>().As<IRoleDal>().InstancePerLifetimeScope();
            build.RegisterType<AliAccountDalImplement>().As<IAliAccountDal>().InstancePerLifetimeScope();
            build.RegisterType<AliOrderDalImplement>().As<IAliOrderDal>().InstancePerLifetimeScope();
            build.RegisterType<OrderDalImplement>().As<IOrderDal>().InstancePerLifetimeScope();
            build.RegisterType<QRCodeDalImplement>().As<IQRCodeDal>().InstancePerLifetimeScope();
            build.RegisterType<PayDal>().As<IPayDal>().InstancePerLifetimeScope();
            build.RegisterType<ApplyDalImplement>().As<IApplyDal>().InstancePerLifetimeScope();
            build.RegisterType<MerchantDalImplement>().As<IMerchantDal>().InstancePerLifetimeScope();
            container = build.Build();
        }
    }
}
